import {defineStore} from 'pinia'
import {listCommon} from '@/api/dashboard'
import {ref} from 'vue'

export const useCommonStore = defineStore('common', () => {
    const data = ref({})

    function setData() {
        listCommon({
            pageNum: 1,
            pageSize: 1000
        }).then((res) => {
            data.value = res.rows
            for (let i = 0; i < 6; i++) {
                data.value[i].content = parseFloat(data.value[i].content)
            }
            data.value[12].content = parseInt(data.value[12].content)
            data.value[17].content = parseFloat(data.value[17].content)

        })
    }

    function startInterval() {
        setInterval(() => {
            setData()
        }, import.meta.env.VITE_APP_INTERVAL)
    }

    return {setData, startInterval, data}
})
